﻿var fileuploaded, isValidType;

function uploadcomplete(sender, args) {
    var updateProgress;
    var filelen = args.get_length();
    //alert(filelen);
    if (filelen > 102400) {
        updateProgress = document.getElementById('ctl00_MainContent_uplProGeneralInfo');
        updateProgress.style.display = "none";

        //var err = new Error();
        //err.name = 'Input Error';
        //err.message = 'File size can not be more than 100 kb';
        document.getElementById('ctl00_MainContent_imgProfilePic').src = "/img/candidate-cv-photo.PNG";

        $("#ctl00_MainContent_lblStatus").show();
        $("#ctl00_MainContent_lblStatus").css("color", "red");
        $("#ctl00_MainContent_lblStatus").text("File size can not be more than 100 kb");

        ClearMsg();
        return;
    }

    if (isValidType != false) {
        fileuploaded = args.get_fileName();
        document.getElementById('ctl00_MainContent_imgProfilePic').style.display = "block";
        $.ajax({
            type: "post",
            url: "EditProfile.aspx/LoadProfilePicPath",
            // data: "{ ProfessionalInfoID : '" + proID + "' }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                //alert('LoadProfilePicPath ' + response.d);
                if (response.d != "") {
                    document.getElementById('ctl00_MainContent_imgProfilePic').src = "/UploadedImage/" + response.d;
                } else {
                    document.getElementById('ctl00_MainContent_imgProfilePic').src = "/img/candidate-cv-photo.PNG";
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                //alert(xmlHttpRequest.statusText);
                //alert(xmlHttpRequest.responseText);
                //alert(textStatus);
                //alert(errorThrown);
            }
        });

        document.getElementById('ctl00_MainContent_uplProGeneralInfo').style.color = "green";
        updateProgress = document.getElementById('ctl00_MainContent_uplProGeneralInfo');
        updateProgress.style.display = "none";

        //document.getElementById('ctl00_MainContent_lblStatus').style.color = "green";
        $("#ctl00_MainContent_lblStatus").css("color", "green");
        $("#ctl00_MainContent_lblStatus").text("Profile picture uploaded");
        ClearMsg();
    }
}
var millisecondsToWait = 5000;

function ClearMsg() {
    //alert('ss');
    //$("#ctl00_MainContent_lblStatus").fadeOut(5000);
    //setTimeout(function () {
    //    $("#ctl00_MainContent_lblStatus").empty();
    //    $("#ctl00_MainContent_lblStatus").text("");
    //}, millisecondsToWait);

};
function uploadStart(sender, args) {
    var filename = args.get_fileName();
    //alert(filename);

    var filext = filename.substring(filename.lastIndexOf(".") + 1);
    if (filext.toLowerCase() == "jpg" || filext.toLowerCase() == "gif" || filext.toLowerCase() == "png" || filext.toLowerCase() == "jpeg") {
        var updateProgress = document.getElementById('ctl00_MainContent_uplProGeneralInfo');
        updateProgress.style.display = "block";
        isValidType = true;
        return true;
    }
    else {
        //alert(filename);

        //var err = new Error();
        //err.name = 'Input Error';
        //err.message = 'Only .jpg/.gif/.png  files are allowed to upload';
        ////$get('lblStatus').textContent = "";
        //document.getElementById('ctl00_MainContent_imgProfilePic').style.color = "red";
        //document.getElementById('ctl00_MainContent_imgProfilePic').src = "/img/candidate-cv-photo.PNG";
        //throw (err);
       
        document.getElementById('ctl00_MainContent_imgProfilePic').src = "/img/candidate-cv-photo.PNG";
        $("#ctl00_MainContent_lblStatus").text("Only .jpg/.gif/.png  files are allowed to upload");
        $("#ctl00_MainContent_lblStatus").show();
        $("#ctl00_MainContent_lblStatus").css("color", "red");
        isValidType = false;
        ClearMsg();
    

        return;
    }


}

function uploaderror(sender, args) {
    //alert(args.get_errorMessage());
    //document.getElementById('ctl00_MainContent_lblStatus').style.color = "red";
    //document.getElementById('ctl00_MainContent_imgProfilePic').src = "/img/candidate-cv-photo.PNG";
    //$("#ctl00_MainContent_lblStatus").show();
    //document.getElementById('ctl00_MainContent_lblStatus').style.visibility = "visible";
    //document.getElementById('ctl00_MainContent_lblStatus').innerHTML = args.get_errorMessage();
    //ClearMsg();
}
